<!DOCTYPE html>
<html>
<head>
    <title>立即购买—小米商城</title>
    <meta charset="utf-8">
    <link rel="icon" href="https://s01.mifile.cn/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="/css/mi.css">
    <link rel="stylesheet" type="text/css" href="/css/shop.css">
    <link rel="stylesheet" type="text/css" href="/css/footer1.css">
    <link rel="stylesheet" type="text/css" href="/font-awesome/css/font-awesome.min.css">
    <script src="/js/jq_3.3.1_mi.js"></script>
    <script type="text/javascript" src="/layui/layui.js"></script>
    <script src="/js/detail.js"></script>
</head>
<script>
    function addToCart() {
        const phoneName = document.getElementById('phoneName').innerText;
        let phonePrice = document.getElementById('totalPrice').innerText;
        // 去除phonePrice 除数字以外的所有信息
        phonePrice = phonePrice.replace(/[^0-9]/g, '');
        const params = new URLSearchParams(window.location.search);
        const data = {
            username: params.get('username'),
            name: phoneName,
            price: phonePrice,
            colour: "黑色",
            version: "24GB+512",
            address: "陕西"
        };
        const requestBody = JSON.stringify(data);

        fetch('/shop/buy/add', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json;charset=UTF-8'
            },
            body: requestBody
        })
            .then(response => response.json())
            .then(data => {
                console.log('Success:', data);
                if (data.code === "200") {
                    // 弹出提示框并在点击确定后跳转到指定链接
                    alert('操作成功');
                    // 获取当前 URL 参数中的 username
                    const params = new URLSearchParams(window.location.search);
                    const username = params.get('username');
                    // 构建新的 URL
                    const newUrl = '/shop_cart' + (username ? `?username=${username}` : '');
                    // 跳转到新的 URL
                    window.location.href = newUrl;
                } else {
                    alert('操作失败');
                }
            })
            .catch((error) => {
                console.error('Error:', error);
            });
    }
</script>
<body>
<div class="header">
    <div class="header_menu">
        <ul class="header_left">
            <li><a href="./index.html">小米商城</a><span>|</span></li>
            <li><a href="#">MIUI</a><span>|</span></li>
            <li><a href="#">IOT</a><span>|</span></li>
            <li><a href="#">云服务</a><span>|</span></li>
            <li><a href="#">小爱分享平台</a><span>|</span></li>
            <li><a href="#">金融</a><span>|</span></li>
            <li><a href="#">有品</a><span>|</span></li>
            <li><a href="#">企业服务</a><span>|</span></li>
            <li><a href="#">SelectRegion</a></li>
        </ul>
        <div class="header_right">
            <ul>
                <!--                <li><a href="#">登录</a><span>|</span></li>-->
                <!--                <li><a href="#">注册</a><span>|</span></li>-->
                <li>
                    <a th:if="${username != null}" th:text="${username}"></a>
                    <a th:unless="${username != null}" href="./login">登录</a><span>|</span>
                </li>
                <li>
                    <a th:unless="${username != null}" href="./register">注册</a><span>|</span>
                </li>
                <li><a href="./order.html">我的订单</a></li>
                <li class="header_right_li"><a th:href="@{'/shop_cart?username=' + ${username}}"><i class="fa fa-shopping-cart"></i>&nbsp; 购物车</a>
                    <!--                    <div>购物车中还没有商品，赶紧选购吧！</div>-->
                </li>
            </ul>
        </div>
    </div>
</div>
<!--   主体内容上半部分   -->
<div class="content-top">
    <div class="content">
        <div class="content_menu">
            <div class="content_menu_pic">
                <img src="/static/img/footlogo.png" class="content_menu_img"
                     style="margin: 5px 0px;margin-right: 10px;">
                <!--                <img src="/static/img/logoAD.gif">-->
            </div>
            <div class="content_menu_ul">
                <ul>
                    <li>小米手机
                        <div class="mi_phone">
                            <div class="mi_phone_div">
                                <div class="mi_phone_div_1">
                                    <div class="mi_phone1">
                                        <div class="new">新品</div>
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone1.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                        <span></span>
                                    </div>
                                    <div class="mi_phone1">
                                        <div class="new">新品</div>
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone2.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                        <span></span>
                                    </div>
                                    <div class="mi_phone1">
                                        <div class="new">新品</div>
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone3.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                        <span></span>
                                    </div>
                                    <div class="mi_phone1">
                                        <div class="new">新品</div>
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone1.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                        <span></span>
                                    </div>
                                    <div class="mi_phone1">
                                        <!-- <div class="new">新品</div> -->
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone1.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                        <span></span>
                                    </div>
                                    <div class="mi_phone1">
                                        <!-- <div class="new">新品</div> -->
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone1.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                    </div>

                                    <div class="clear"></div>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>红米
                        <div class="mi_phone">
                            <div class="mi_phone_div">
                                <div class="mi_phone_div_1">
                                    <div class="mi_phone1">
                                        <div class="new">新品</div>
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone7.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                        <span></span>
                                    </div>
                                    <div class="mi_phone1">
                                        <div class="new">新品</div>
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone8.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                        <span></span>
                                    </div>
                                    <div class="mi_phone1">
                                        <div class="new">新品</div>
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone9.jpg">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                        <span></span>
                                    </div>
                                    <div class="mi_phone1">
                                        <div class="new">新品</div>
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone1.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                        <span></span>
                                    </div>
                                    <div class="mi_phone1">
                                        <div class="new">新品</div>
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone1.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                        <span></span>
                                    </div>
                                    <div class="mi_phone1">
                                        <div class="new">新品</div>
                                        <div class="mi_phone_shop">
                                            <img src="/static/img/phone/phone1.png">
                                            <br>
                                            <a href="">小米2s</a>
                                            <br>
                                            <a href="" style="color:#FF6A00;">3299元</a>
                                        </div>
                                    </div>
                                    <div class="clear"></div>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>电视</li>
                    <li>笔记本</li>
                    <li>盒子</li>
                    <li>新品</li>
                    <li>路由器</li>
                    <li>智能硬件</li>
                    <li>服务</li>
                    <li>社区</li>
                </ul>
            </div>
            <div class="content-form">
                <form>
                    <input type="text" name="">
                    <div class="content-form-a"><a href="">电视新品</a> <a href="">618预热</a></div>
                    <div class="botton"><i class=" fa fa-search"></i></div>

                </form>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <div class="detail">
        <div class="content">
            <div class="detail_left">
                <b th:text="${phoneInfo.name}"></b><a href="#"></a>
            </div>
            <div class="detail_right">
                <a href="">概述</a><span></span>
                <a href="">图集</a><span></span>
                <a href="">参数</a><span></span>
                <a href="">F码通道</a><span></span>
                <a href="">用户评价</a>
            </div>
        </div>
    </div>

    <div class="shop_detail">
        <div class="shop_detail_pic">
            <div class="layui-carousel" id="test1" lay-filter="test1">
                <div carousel-item="">
                    <!--                                        <div><img th:src="@{${phoneInfo.img}}" style="width: 100% ;height: 100%"></div>-->
                    <div><img th:src="@{'/' + ${phoneInfo.img}}" style="width: 100%; height: 100%;"></div>
                    <!--                    <div><img src="/static/img/lun/2.jpg"></div>-->
                    <!--                    <div><img src="/static/img/lun/3.jpg"></div>-->
                    <!--                    <div><img src="/static/img/lun/6.png"></div>-->
                </div>
            </div>
        </div>
        <div class="shop_detail_menu">
            <h1 id="phoneName" th:text="${phoneInfo.name}"></h1>
            <p th:text="${phoneInfo.info}"></p>
            <!-- <h2 th:text="${phoneInfo.price}"></h2> -->
            <div class="detail_map">
                <i class="fa fa-map-marker " style="color:#ccc;font-size: 15px;"></i>
                <span>北京 北京市 东城区 永定门外街道
                <a href="" style="color:#FF6A00;"> 修改 </a>
            </span><br>
                <span style="color:#FF6A00;margin-left: 12px;">有现货</span>
            </div>

            <div class="shop_detail_much">
                <p>选择版本</p>
                <div class="detail_much_left" th:each="entry : ${versionList}">
                    <th:block th:text="${entry.key} + ' '"></th:block>
                    <span th:text="${entry.value} + '元'" th:data-val="${entry.value}"></span>
                </div>
            </div>
            <div class="clear"></div>
            <div class="shop_detail_zj">
                <div>
                    <p th:text="${phoneInfo.name}"> 6GB+64GB 黑色</p><span id="phonePrice"></span>
                    <div class="clear"></div>
                </div>
                <p id="totalPrice" style="color:#FF6A00;font-size: 25px;margin-left: 30px;">总计&nbsp;：&nbsp;元</p>
            </div>
            <button class="shop_detail_cart" onclick="addToCart()">加入购物车</button>
            <!--            <button class="shop_detail_cart" type="submit">加入购物车</button>-->
            <p>
                <i class="fa fa-check-circle-o"></i> 7天无理由退货
                <i class="fa fa-check-circle-o"></i> 15天质量问题换货
                <i class="fa fa-check-circle-o"></i> 365天保修
            </p>
        </div>
        <!--        <form action="/shop/buy/add" method="post">-->
        <!--            <div class="shop_detail_menu">-->
        <!--                <h1 th:text="${phoneInfo.name}"></h1>-->
        <!--                <p th:text="${phoneInfo.info}"></p>-->
        <!--                &lt;!&ndash;            <h2 th:text="${phoneInfo.price}"></h2>&ndash;&gt;-->
        <!--                <div class="detail_map">-->
        <!--                    <i class="fa fa-map-marker " style="color:#ccc;font-size: 15px;"></i>-->
        <!--                    <span>北京   北京市   东城区  永定门外街道  <a href="" style="color:#FF6A00;"> 修改 </a> </span><br>-->
        <!--                    <span style="color:#FF6A00;margin-left: 12px;">有现货</span>-->
        <!--                </div>-->

        <!--                <div class="shop_detail_much">-->
        <!--                    <p>选择版本</p>-->
        <!--                    <div class="detail_much_left" th:each="entry : ${versionList}">-->
        <!--                        <th:block th:text="${entry.key} + ' '"></th:block>-->
        <!--                        <span th:text="${entry.value} + '元'" th:data-val="${entry.value}"></span>-->
        <!--                    </div>-->
        <!--                </div>-->
        <!--                <div class="clear"></div>-->
        <!--                <div class="shop_detail_zj">-->
        <!--                    <div>-->
        <!--                        <p th:text="${phoneInfo.name}"> 6GB+64GB 黑色</p><span id="phonePrice"></span>-->
        <!--                        <div class="clear"></div>-->
        <!--                    </div>-->
        <!--                    <p id="totalPrice" style="color:#FF6A00;font-size: 25px;margin-left: 30px;">总计&nbsp;：&nbsp;元</p>-->
        <!--                </div>-->
        <!--                &lt;!&ndash;                            <div class="shop_detail_cart" type="submit">加入购物车</div>&ndash;&gt;-->
        <!--                <button class="shop_detail_cart" type="submit">加入购物车</button>-->
        <!--                <p><i class="fa fa-check-circle-o"></i> 7天无理由退货 <i class="fa fa-check-circle-o"></i> 15天质量问题换货-->
        <!--                    <i class="fa fa-check-circle-o"></i> 365天保修 </p>-->
        <!--            </div>-->
        <!--        </form>-->

        <!--        <div class="shop_detail_color">-->
        <!--            <p>选择颜色</p>-->
        <!--            <div class="detail_color_left detail_color_left_checked"><span style="background:#F6E6D8; "></span> 金色-->
        <!--            </div>-->
        <!--            <div class="detail_color_left"><span style="background:#3C3F43;"></span> 深灰</div>-->
        <!--            <div class="detail_color_left"><span style="background:#D93239;"></span> 亮红</div>-->
        <!--            <div class="detail_color_left"><span style="background:#3871B7;"></span> 亮蓝</div>-->
        <!--        </div>-->
        <!--        <div class="clear"></div>-->

        <div class="clear"></div>
    </div>
    <div class="detail_content">
        <div class="detail_content_1">
            <p>特别说明</p>
            <img src="/static/img/sm.jpg">
            <p>官方微信</p>
            <img src="/static/img/2.jpg">
        </div>
    </div>
    <!--   网页底部   -->
    <div class="footer-top">
        <div class="footer-top_li">
            <div class="footer-top_li_1">
                <a href="#"><i class="fa fa-wrench"></i>预约维修服务</a><span></span>
                <a href="#"><i class="fa fa-rotate-right "></i>7天无理由退货</a><span></span>
                <a href="#"><i class="fa fa-refresh"></i>15天免费换货</a><span></span>
                <a href="#"><i class="fa fa-gift"></i>满150元包邮</a><span></span>
                <a href="#"><i class="fa fa-map-marker"></i>520余家售后网点</a>
            </div>
            <span class="separate"></span>
            <div class="footer-top_li_2">
                <div class="footer-top_li_a">
                    <dl>
                        <dt>帮助中心</dt>
                        <dd><a href="">账户管理</a></dd>
                        <dd><a href="">购物指南</a></dd>
                        <dd><a href="">订单操作</a></dd>
                    </dl>
                    <dl>
                        <dt>服务支持</dt>
                        <dd><a href="">售后政策</a></dd>
                        <dd><a href="">自助服务</a></dd>
                        <dd><a href="">相关下载</a></dd>
                    </dl>
                    <dl>
                        <dt>线下门店</dt>
                        <dd><a href="">小米之家</a></dd>
                        <dd><a href="">服务网点</a></dd>
                        <dd><a href="">授权体验店</a></dd>
                    </dl>
                    <dl>
                        <dt>关于小米</dt>
                        <dd><a href="">了解小米</a></dd>
                        <dd><a href="">加入小米</a></dd>
                        <dd><a href="">投资者关系</a></dd>
                    </dl>
                    <dl>
                        <dt>关注我们</dt>
                        <dd><a href="">新浪微博</a></dd>
                        <dd><a href="">官网微博</a></dd>
                        <dd><a href="">联系我们</a></dd>
                    </dl>
                    <dl>
                        <dt>特色服务</dt>
                        <dd><a href="">F码通道</a></dd>
                        <dd><a href="">礼物码</a></dd>
                        <dd><a href="">防伪查询</a></dd>
                    </dl>
                    <div class="connect">
                        <p class="telephone">Feir-520-1314</p>
                        <p class="time">周一至周日 8:00-18:00<br>(仅收市话费)</p>
                        <button><span class="fa fa-commenting "></span> 联系客服</button>
                    </div>
                </div>
                <div class="footer-top_li_b"></div>
            </div>
        </div>

    </div>
    <div class="footer-bottom">
        <div class="footer-bottom_li">
            <div class="footer-bottom_li_1">
                <img src="/static/img/footlogo.png" alt="" class="logoBottom">
            </div>
            <div class="footer-bottom_li_2">
                <div class="footer-bottom_li_a">
                    <ul>
                        <li>小米商城<span></span></li>
                        <li>MIUI<span></span></li>
                        <li>米家<span></span></li>
                        <li>米聊<span></span></li>
                        <li>多看<span></span></li>
                        <li>游戏<span></span></li>
                        <li>路由器<span></span></li>
                        <li>米粉卡<span></span></li>
                        <li>政企服务<span></span></li>
                        <li>小米天猫店<span></span></li>
                        <li>隐私政策<span></span></li>
                        <li>问题反馈<span></span></li>
                        <li>Select Region</li>
                    </ul>
                </div>
                <div class="footer-bottom_li_b">
                    <a href="">©mi.com</a>
                    京ICP证110507号
                    <a href="">京ICP备10046444号</a>
                    <a href="">京公网安备11010802020134号</a>
                    <a href="">京网文[2014]0059-0009号</a>
                    <br>
                    违法和不良信息举报电话：185-0130-1238，本网站所列数据，除特殊说明，所有数据均出自我司实验室测试
                </div>
            </div>
            <div class="footer-bottom_li_3">
                <img src="/static/img/footericon1.png" alt="" class="icon">
                <img src="/static/img/footericon2.png" alt="" class="icon">
                <img src="/static/img/footericon3.png" alt="" class="icon">
                <img src="/static/img/footericon4.png" alt="" class="icon">
                <img src="/static/img/footericon5.png" alt="" class="icon">
            </div>
            <div class="footer-bottom_li_4">
                探索黑科技，小米为发烧而生！
            </div>
        </div>
    </div>
    <script>
        layui.use('carousel', function () {
            var carousel = layui.carousel;
            //建造实例
            carousel.render({
                elem: '#test1'
                , width: '560px' //设置容器宽度
                , height: '560px'
                , arrow: 'always' //始终显示箭头
                //,anim: 'updown' //切换动画方式
            });
        });
    </script>
</body>
</html>